﻿using System;
using System.Collections.Generic;

namespace XamlMvp.Modelling
{
    public class Hydrator<T> : IHydratable<T>
    {
        readonly string key;

        public Hydrator(string key)
        {
            this.key = key;
        }

        public void FreezeObject(IDictionary<string, object> state, T obj)
        {
            state[key] = obj;
        }

        public void FreezeKind<TKind>(IDictionary<string, object> state, TKind obj)
        {
            throw new NotSupportedException("Cannot do this for simple hydrations");
        }

        public T HydrateObject(System.Collections.Generic.IDictionary<string, object> state)
        {
            if (state.ContainsKey(key))
            {
                return (T)state[key];
            }
            return default(T);
        }
    }
}
